package com.situ.achievementsystem.score.service;

import java.util.List;

import com.situ.achievementsystem.score.dao.ScoreDao;
import com.situ.achievementsystem.score.model.ScoreModel;

public class ScoreService {

private ScoreDao dao = new ScoreDao();
	
	public String insert(ScoreModel model) {
		return selectModel(model) == null?dao.insert(model):"rgp";
	}
	
	public String delete(ScoreModel model) {
		return dao.delete(model);
	}
	
	public String update(ScoreModel model) {
		return dao.update(model);
	}
	
	public List<ScoreModel> selectList(ScoreModel model) {
		String code = model.getScore();
		code = code ==null || code.trim().isEmpty()?"":code;
		model.setScore("%" + code + "%");
		String name = model.getName();
		name = name ==null || name.trim().isEmpty()?"":name;
		model.setName("%" + name + "%");
		return dao.select(model);
	}
	
	public ScoreModel selectModel(ScoreModel model) {
		ScoreModel temp = new ScoreModel();
		temp.setName(model.getName());
		List<ScoreModel> list = dao.select(model);
		if(list==null || list.isEmpty())
			return null;
		return list.get(0);
	}
}
